﻿using System;
using System.Globalization;
namespace System {
	static class Parser {
		#region Public
		public static bool TryParse(String value, out bool result) {
			return bool.TryParse(value, out result);
		}

		public static bool TryParse(String value, out ushort result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return ushort.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out ushort result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return ushort.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out uint result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return uint.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out uint result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return uint.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out ulong result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return ulong.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out ulong result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return ulong.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out short result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return short.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out short result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return short.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out int result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return int.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out int result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return int.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out long result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return long.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out long result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return long.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out double result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return double.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out double result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return double.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out float result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return float.TryParse(value, out result);
		}
		public static bool TryParse(String value, NumberStyles style, IFormatProvider provider, out float result) {
			if (String.IsNullOrEmpty(value)) {
				result = 0;
				return false;
			}
			return float.TryParse(value, style, provider, out result);
		}

		public static bool TryParse(String value, out DateTime result) {
			if (String.IsNullOrEmpty(value)) {
				result = DateTime.MinValue;
				return false;
			}
			return DateTime.TryParse(value, out result);
		}
		public static bool TryParse(String value, DateTimeStyles style, IFormatProvider provider, out DateTime result) {
			if (String.IsNullOrEmpty(value)) {
				result = DateTime.MinValue;
				return false;
			}
			return DateTime.TryParse(value, provider, style, out result);
		}

		public static bool TryParse(String value, out Guid result) {
			if (String.IsNullOrEmpty(value)) {
				result = Guid.Empty;
				return false;
			}
			result = new Guid(value);
			return true;
		}
		#endregion
	}
}